/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdMeshModelStructureDefinitionBo;
import com.comac.ins.isfd.domain.bo.query.IsfdMeshModelStructureDefinitionQueryBo;
import com.comac.ins.isfd.domain.vo.IsfdMeshModelAndSectionInfoVo;
import com.comac.ins.isfd.domain.vo.IsfdMeshModelStructureDefinitionTreeNodeVo;
import com.comac.ins.isfd.domain.vo.IsfdMeshModelStructureDefinitionVo;
import com.comac.ins.isfd.service.IIsfdMeshModelStructureDefinitionService;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;


/**
 * 自然网格模型库-构型定义
 *
 * @author hxloongs
 * @date 2025-01-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/meshModelStructureDefinition")
public class IsfdMeshModelStructureDefinitionController extends BaseController {

    @Autowired
    private IIsfdMeshModelStructureDefinitionService isfdMeshModelStructureDefinitionService;

    /**
     * 查询自然网格模型库-构型定义列表
     */
    @SaCheckPermission("isfd:meshModelStructureDefinition:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdMeshModelStructureDefinitionVo> list(@RequestBody IsfdMeshModelStructureDefinitionQueryBo bo) {
        return isfdMeshModelStructureDefinitionService.queryPageList(bo);
    }

    /**
     * 查询【模型库结构定义树】列表-树结构
     */
    @SaCheckPermission("isfd:meshModelStructureDefinition:list")
    @GetMapping("/tree")
    public R<List<IsfdMeshModelStructureDefinitionTreeNodeVo>> listTree() {
        return R.ok(isfdMeshModelStructureDefinitionService.listTree());
    }

    /**
     * 获取自然网格模型库-构型定义详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:meshModelStructureDefinition:query")
    @GetMapping("/{id}")
    public R<IsfdMeshModelStructureDefinitionVo> getInfo(@NotNull(message = "主键不能为空")
                                                         @PathVariable Long id) {
        return R.ok(isfdMeshModelStructureDefinitionService.queryById(id));
    }

    /**
     * 新增自然网格模型库-构型定义
     */
    @SaCheckPermission("isfd:meshModelStructureDefinition:add")
    @Log(title = "自然网格模型库-构型定义", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@RequestBody IsfdMeshModelStructureDefinitionBo bo) {
        return toAjax(isfdMeshModelStructureDefinitionService.insertByBo(bo));
    }

    /**
     * 修改自然网格模型库-构型定义
     */
    @SaCheckPermission("isfd:meshModelStructureDefinition:update")
    @Log(title = "自然网格模型库-构型定义", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/update")
    public R<Void> update(@RequestBody IsfdMeshModelStructureDefinitionBo bo) {
        return toAjax(isfdMeshModelStructureDefinitionService.updateByBo(bo));
    }

    /**
     * 删除自然网格模型库-构型定义
     */
    @SaCheckPermission("isfd:meshModelStructureDefinition:remove")
    @Log(title = "自然网格模型库-构型定义", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> remove(@NotNull(message = "主键不能为空")
                          @PathVariable Long id) {
        return toAjax(isfdMeshModelStructureDefinitionService.deleteWithValidByIds(id));
    }

    /**
     * 获取所有部段名称
     */
    @SaCheckPermission("isfd:meshModelStructureDefinition:query")
    @GetMapping("/getAllSectionNames")
    public R<List<IsfdMeshModelStructureDefinitionVo> > getAllSectionNames(@RequestParam(value = "filterSection",required = false) Boolean filterSection) {
        return R.ok(isfdMeshModelStructureDefinitionService.getAllSectionNames(filterSection));
    }

    /**
     * 根据部段名称查询机型-部段信息接口
     */
    @SaCheckPermission("isfd:meshModelStructureDefinition:query")
    @GetMapping("/getModelAndSectionInfoBySectionName")
    public R<List<IsfdMeshModelAndSectionInfoVo>> getModelAndSectionInfoBySectionName(@RequestParam("sectionNames") String sectionNames) {
        return R.ok(isfdMeshModelStructureDefinitionService.getModelAndSectionInfoBySectionName(sectionNames));
    }


}
